package main

import (
	"fmt"
	"math/rand"
	"os"
	"time"
)

func main() {

	students := []string{"张三", "李四", "王五", "赵六", "钱七"}

	rand.Seed(time.Now().UnixNano())

	for {

		if len(students) == 0 {
			fmt.Println("所有同学都已经回答完毕，程序退出。")
			os.Exit(0)
		}

		fmt.Println("按任意键抽取同学名字，按 q 退出：")
		var input string
		_, _ = fmt.Scanln(&input)

		if input == "q" {
			fmt.Println("程序退出。")
			os.Exit(0)
		}

		index := rand.Intn(len(students))
		selectedStudent := students[index]
		fmt.Printf("被抽中的同学是：%s\n", selectedStudent)

		students = append(students[:index], students[index+1:]...)
	}
}

